package org.wattdepot.cli.commands;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

/**
 * This class tests the fuel types command of the CommandLineInterface's actual commands.
 * @author David Mau
 */
public class TestCommandFuelTypes {
String cr = System.getProperty("line.separator");

  /**
   * Tests the fuel types command.
   */
  @Test
  public void testFuelTypes() {
    // Create a new help command object.
    FuelTypesCommand command = new FuelTypesCommand( null );
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_OAHU_GRID" );
    
    // Get the known output from the command
    String sourceOutput = command.doCommand( args );
    
    String knownOutput = "waste : SIM_HPOWER";
    knownOutput = knownOutput.concat(cr);
    knownOutput = knownOutput.concat("diesel : SIM_WAIAU_9,SIM_WAIAU_10");
    knownOutput = knownOutput.concat(cr);
    knownOutput = knownOutput.concat("coal : SIM_AES");
    knownOutput = knownOutput.concat(cr);
    knownOutput = knownOutput.concat("LSFO : SIM_KAHE_1,SIM_KAHE_2,SIM_KAHE_3,SIM_KAHE_4,");
    knownOutput = knownOutput.concat("SIM_KAHE_5,SIM_KAHE_6,SIM_KAHE_7,SIM_WAIAU_5,");
    knownOutput = knownOutput.concat("SIM_WAIAU_6,SIM_WAIAU_7,SIM_WAIAU_8,SIM_HONOLULU_8,");
    knownOutput = knownOutput.concat("SIM_HONOLULU_9,SIM_KALAELOA");
    knownOutput = knownOutput.concat(cr);
    
    // Check to see if the expected and actual outputs match
    int result = sourceOutput.compareTo(knownOutput);
    assertSame("Checking fuel types command", result, 0);
    
    // Ready another known output.
    args = Arrays.asList( "SIM_IPP" );
    // Get the known output from the command
    sourceOutput = command.doCommand( args );
    
    // Ready known output.
    knownOutput = "waste : SIM_HPOWER";
    knownOutput = knownOutput.concat(cr);
    knownOutput = knownOutput.concat("coal : SIM_AES");
    knownOutput = knownOutput.concat(cr);
    knownOutput = knownOutput.concat("LSFO : SIM_KALAELOA");
    knownOutput = knownOutput.concat(cr);
    
    // Compare the results.
    result = sourceOutput.compareTo(knownOutput);
    assertSame("Checking fuel types command", result, 0);
  }
  
  /**
   * Test bad source detection for the fuel types command.
   */
  @Test
  public void testSummaryBadSource() {
    // Create a new fuel types command object.
    FuelTypesCommand command = new FuelTypesCommand(null);
    // Create a new List to store the args for known data
    List<String> args = Arrays.asList("SATURN");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the right error returned.
    assertTrue("Checking for correct response to bad source", sourceOutput
        .contains(WattDepotCliCommand.resourceNotFound));
  }
  
  /**
   * Tests to see if the fuel types command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new fuel types command object.
    FuelTypesCommand command = new FuelTypesCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess fuel types argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the fuel types command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new fuel types command object.
    FuelTypesCommand command = new FuelTypesCommand(null);
    // Create a new List to store the args
    List<String> args = new ArrayList<String>();
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking fuel types handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
